<style type="text/css">
#create-lesson-block {
	padding: 20px;
}

#create-lesson-form {
	
}

#create-lesson-form label {
	width: 140px;
	display: inline-block;
	vertical-align: top;
}
</style>
<div id="create-lesson-block">
	<div><strong>สร้างบทเรียน</strong></div>
	<form id="create-lesson-form" method="post" action="<?php echo $this->createUrl('lesson/create');?>">
		<label>หัวข้อ</label><input type="text" name="create[lesson_name]" /><br />
		<label>รหัสผ่าน</label><input type="text" name="create[password]" /><br />
		<label>รายละเอียดเพิ่มเติม</label><textarea name="create[lesson_detail]"></textarea><br />
		<label></label><input type="submit" value="create" />
	</form>
</div>
<script type="text/javascript">
$(function(){
	$('#create-lesson-form').submit(function(event){
		event.preventDefault();
		var sendData = {};
		$(this).find('input[name],textarea[name]').each(function(index){
			sendData[$(this).attr('name')] = $(this).val();
		});
		$.ajax($(this).attr('action'),{
			'data' : sendData,
			'type' : 'POST',
			'success' : function(data){
				window.location.href = '<?php echo Yii::app()->request->baseUrl;?>/lesson/'+data.lesson.lesson_id;
			},
			'dataType' : 'JSON'
		});
	});
});
</script>